package Demo06.Demo06;

public class Demo06_Tset {
    public static void main(String[] args) {
        Object o = new Object();
        Shuzi shuzi = new Shuzi(o);
        Zimu zimu = new Zimu(o);
        Thread thread1 = new Thread(shuzi);
        Thread thread2 = new Thread(zimu);
        thread1.start();
        thread2.start();
    }
}
class Shuzi implements Runnable {
    private Object obj;

    public Shuzi(Object obj) {
        this.obj = obj;
    }

    @Override
    public void run() {
        synchronized (obj) {
            for (int i = 1; i < 53; i++) {
                System.out.println(i);
                if (i % 2 == 0) {
                    obj.notify();

                    try {
                        obj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

}
class Zimu implements Runnable {
    private Object obj;

    public Zimu(Object obj) {
        this.obj = obj;
    }

    @Override
    public void run() {
        synchronized (obj) {
            for (int i = 1; i < 26; i++) {
                System.out.println((char)(i+'A'));
                obj.notifyAll();
                try {
                    obj.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

